import 'package:dio/dio.dart';

/***
 * 网络请求get 加如token
 */
class HttpRequest {
  static Dio dio;
  BaseOptions options;

  HttpRequest([BaseOptions baseOptions]) {
    if (baseOptions == null) {
      baseOptions = BaseOptions(
        baseUrl: 'http://121.196.226.246:84',
        connectTimeout: 5000,
        receiveTimeout: 3000,
      );
    }
    this.options = baseOptions;
    dio = Dio(options);
    dio.interceptors
        .add(InterceptorsWrapper(onRequest: (RequestOptions options) {
      return options;
    }, onResponse: (Response response) {
      return response;
    }, onError: (DioError e) {
      print('请求错误" $e');
      return e;
    }));
  }

//get  请求
  Future get(String path,
      {queryParameters, Options option, CancelToken cancelToken}) async {
    return await dio.get(path,
        queryParameters: queryParameters,
        options: option,
        cancelToken: cancelToken);
  }

  HttpRequest httpRequest = new HttpRequest();
}
